var classifyGuy = {
    initDown: function () {
        BY.headerDown.hide || ($(".header-site").height("1.89rem"), $(".header-fix").css("top", "1rem"), $(".section-cateList").css("top", $(".main-header").height()), BY.headerDown.callBack = function () {
            $(".header-site").height(".89rem"), $(".header-fix").css("top", "0"), $(".section-firstCate").css("top", $(".main-header").height()), $(".section-cateList").css("top", $(".main-header").height()), classifyGuy.firstCateScroll.refresh()
        })
    },
    initFirstCate: function () {
        $(".section-firstCate").css("top", $(".main-header").height()), this.firstCateScroll = new IScroll(".section-firstCate > div", {
            eventPassthrough: !1,
            scrollX: !1,
            scrollY: !0,
            preventDefault: !1
        }), this.contentScroll = new IScroll(".section-cateList > div", {
            eventPassthrough: !1,
            scrollX: !1,
            scrollY: !0,
            preventDefault: !1,
            probeType: 3
        }), this.contentScroll.on("scrollEnd", function () {
            $(".section-cateList > div").trigger("scroll")
        }), this.firstCateScroll.on("scrollStart", this.stopDefault), this.contentScroll.on("scrollStart", this.stopDefault)
    },
    _firstCateSlider: function (t) {
        this.firstCateScroll.scrollToElement($('[data-cateId="' + t + '"]')[0], 200, !0, !0)
    },
    stopDefault: function () {
        document.addEventListener("touchmove", function (t) {
            t.preventDefault()
        }, !1)
    },
    bindFirstCateHandle: function () {
        var t = $(".section-firstCate"), e = t.find("li"), i = this;
        Array.prototype.forEach.call(e, function (t) {
            $(t).tap(function () {
                var t = $(this).attr("data-cateId");
                i._firstCateAction(t), i._historyHandle(t)
            })
        })
    },
    _firstCateAction: function (t) {
        $(".section-firstCate li").removeClass("firstCate-active"), $(".cateList-first").addClass("none"), null == t || "" == t ? ($(".section-firstCate li").eq(0).addClass("firstCate-active"), $(".cateList-first").eq(0).removeClass("none")) : ($(".section-firstCate").find('[data-cateId="' + t + '"]').addClass("firstCate-active"), $(".section-cateList").find('[data-cateId="' + t + '"]').removeClass("none")), this._firstCateSlider(t), classifyGuy.contentScroll.refresh()
    },
    _historyHandle: function (t) {
        history.pushState({}, "", "?categoryId=" + t)
    },
    _listenHistory: function () {
        window.addEventListener("popstate", function () {
            classifyGuy._firstCateAction(BY.string.getUrlParam("categoryId"))
        })
    },
    searchHandle: function () {
        var t, e = [], i = function () {
            e.push({
                pclk: "home.search",
                pclkp: "",
                pn: "search_req",
                pnp: ""
            }), t = BY.trace.assemblyParam(e), BY.trace.setData(t, function () {
                window.location.href = window.ControllerSite + "/search/searchResult"
            })
        };
        $(".header-search").click(i)
    },
    targetBanner: function () {
        function t(t, i) {
            switch (i) {
                case"1":
                    e = window.ControllerSite + "/products/" + t.suId + ".html";
                    break;
                case"2":
                    e = t.url;
                    break;
                case"3":
                    e = window.ControllerSite + "/classify/supplierHome?supplierId=" + t.supplierID;
                    break;
                case"4":
                    e = window.ControllerSite + "/classify/middlePage?pageType=thirdClassify&categoryId=" + t.categoryID;
                    break;
                case"5":
                    e = window.ControllerSite + "/classify/marketList?type=1&title=" + encodeURIComponent(t.title);
                    break;
                case"6":
                    e = window.ControllerSite + "/classify/marketList?type=2&title=" + encodeURIComponent(t.title);
                    break;
                case"7":
                    e = window.ControllerSite + "/classify/newproductList?title=" + encodeURIComponent(t.title);
                    break;
                case"8":
                    e = window.ControllerSite + "/classify/middlePage?pageType=productCollect&productAggregationId=" + t.productAggregationId;
                    break;
                case"9":
                    e = window.ControllerSite + "/classify/middlePage?pageType=classifyCollect&categoryAggregationId=" + t.categoryAggregationId
            }
        }

        var e = "";
        $(".top-banner").on("click", function (i) {
            i.preventDefault();
            var a = $(this), s = a.attr("idx"), r = category[s].categoryImage.ext,
                o = category[s].categoryImage.jumpType;
            t(r, o), window.location.href = e
        })
    }, init: function () {
        this.searchHandle(), this.initDown(), this.initFirstCate(), this._firstCateSlider(BY.string.getUrlParam("categoryId") || $(".section-firstCate li").eq(0).attr("data-cateid")), this.bindFirstCateHandle(), this._listenHistory(), BY.tabChange.init("classify"), $(".section-cateList img").picLazyLoad(), BY.share.init({
            title: "类目列表-必要商城",
            link: window.location.href,
            desc: "必要商城，买大牌制造商产品，上必要"
        }), this.targetBanner(), BY.cookie.get("cpssource") && BY.headerDown.callBack()
    }
};
$(function () {
    classifyGuy.init()
});